package controller;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import DAO.DAOFactory;
import bizlogic.Manager;
import DAO.BookDetailsDAO;

import model.BookDetailsDTO;

/**
 * Servlet implementation class DeleteController
 */
@WebServlet(description = "For deleting booking request before approval by manager", urlPatterns = { "/DeleteController" })
public class DeleteController extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DeleteController() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doDeletion(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doDeletion(request, response);
	}

	/**
	 * @see HttpServlet#doDelete(HttpServletRequest, HttpServletResponse)
	 */
	private void doDeletion(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		String bookingID = request.getParameter("BookingID");
		Integer bID=Integer.valueOf(bookingID);
		Manager m = new Manager();
		BookDetailsDTO bd = m.FindByBookingID(bID);
		System.out.println(bd.toString());
		m.delete(bd);
		RequestDispatcher rd = request.getRequestDispatcher("/BookDetailsController");
		rd.forward(request, response);
	}

}
